Skip to content

Enhance Logging and Resilience Components #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Sep 23, 2024
Merged

Enhance Logging and Resilience Components #1

merged 32 commits into from
Sep 23, 2024

Conversation

walmir-silva
Copy link
Contributor

This pull request includes updates to file handler error handling, configuration refactoring, and test suite enhancements for comprehensive coverage.

Changes:

  • Removed test git processor.
    
  • Refactored logging system to improve error handling and resilience.
    
  • Enhanced file handler error handling and added corresponding tests.
    
  • Updated configuration and refactored tests for improved reliability.
    
  • Implemented optional context parameters with thresholds.
    
  • Improved AsyncLogProcessor with enhanced encapsulation.
    
  • Expanded LoggerServiceProviderTest for 100% coverage.
    
  • Enhanced logger handler factory and service provider.
    
  • Added validation for optional log configurations.
    
  • Refactored and enhanced logging anonymization.
    
  • Encapsulated log level colors within the LogLevel enum.
    
  • Migrated Slack logger implementation to use chat.postMessage.
    
  • Updated logging configuration and handlers.
    
  • Fixed issues in LoggerRegistry and SlackClient tests.
    
  • Enhanced unit tests for logging classes.
    
  • Added tests for introspection processor behavior.
    
  • Removed outdated test files.
    
  • Added 'final' to classes in the 'tests' folder for optimization.
    
  • Refactored LoggerHandlerFactory and added new test cases.
    
  • Improved logging factories and extended test coverage.
    

- Updated JsonFormatter.php for improved JSON structure handling.
- Refined RotatingFileHandler.php to optimize file rotation logic.
- Adjusted LogLevel.php for better log level categorization.
- Enhanced CircuitBreaker.php to improve resilience features.
- Modified SizeBasedRotator.php for efficient log file rotation based on size.
- Updated AsyncLoggerTest.php to include new async logging scenarios.
- Refined RotatingFileHandlerTest.php to cover additional test cases.
- Improved SlackHandlerTest.php for better integration testing with Slack.
- Enhanced LoggerManagerTest.php to ensure comprehensive logger management testing.
- Updated SamplerTest.php to test enhanced sampling utilities.
- Refined SlackClientTest.php to improve Slack client test coverage.
- modified: docker-compose.yml
  - Updated service configurations for better compatibility and performance.

- new file: invalidPath
  - Added a placeholder file to simulate an invalid path scenario in tests.

- modified: src/Handler/AbstractFileHandler.php
  - Improved directory creation logic with better error handling.
  - Added checks for directory writability.
  - Included detailed exceptions for invalid and non-writable paths.

- modified: tests/Handler/FileHandlerTest.php
  - Added tests for invalid path handling.
  - Enhanced tests for non-writable directory scenarios.
  - Verified that exceptions are thrown correctly for invalid and non-writable paths.

- modified: tests/Logger/LoggerBuilderTest.php
  - Adjusted test cases to align with the new error handling logic in FileHandler.
  - Improved test coverage for logger builder functionalities.
- Modified Makefile to streamline build processes.
- Updated composer.json to include new dependencies and update versions.
- Revised tests in Handler/FileHandlerTest.php to address recent changes.
- Removed obsolete tests from Util directory:
  - AssetPublisherTest.php
  - ComposerScriptsTest.php
  - ConfigGeneratorTest.php
- Modified ConfigHelperTest.php to align with updated configuration and utility changes.
- Updated LoggerConfiguration class for better handling of nested keys and configuration values.
  - Implemented the set function to define nested values in the configuration.
  - Implemented the get function to retrieve nested values from the configuration, with support for default values.
  - Added the load function to load the configuration from a file and validate its format.
  - Improved helper functions for handling nested keys and values.

- Updated LoggerFactory class to correctly utilize logger configurations.
  - Modified the createLogger function to support different types of handlers and formatters.
  - Updated createQueryLogger, createPerformanceLogger, and createErrorLogger functions to use complete configurations.

- Updated LoggerServiceProvider class to register additional loggers based on configurations.
  - Added support to register query, performance, and error loggers based on provided configurations.
  - Checked for the presence of configurations and initialized additional loggers as needed.

- Updated EnvLoader and EnvParser classes for better support of environment variable loading and parsing.
  - Added load function in EnvLoader to load environment variables from a .env file.
  - Added parse function in EnvParser to interpret environment values as booleans, integers, floats, or strings.

- Added checks and exception handling to ensure robustness of the code.
…njection and testability

- Updated LoggerServiceProvider class to use dependency injection
  - Modified constructor to accept LoggerConfiguration, LoggerFactory, and LoggerRegistry instances
  - Removed static method calls, improving testability and flexibility

- Refactored LoggerFactory class to be instantiable instead of static
  - Converted all static methods to instance methods
  - Improved createLogger method to support various handler and formatter configurations
  - Updated specialized logger creation methods (query, performance, error) to use instance methods

- Refactored LoggerRegistry class to be instantiable instead of static
  - Converted static properties and methods to instance ones
  - Improved management of logger instances with private $loggers property

- Updated initialization process for the logging system
  - Created instances of LoggerFactory and LoggerRegistry
  - Modified LoggerServiceProvider instantiation to inject dependencies
  - Updated logger retrieval process to use instance methods of LoggerRegistry
…ion and exception handling

- Encapsulated Fiber logic in a dedicated `startFiber` method to improve code clarity.
- Implemented `processRemaining` method to ensure all queued logs are processed before object destruction.
- Ensured `processRemaining` is called in the destructor to avoid losing any log records.
- Consolidate existing tests into a comprehensive testRegisterAllLoggers
- Add new test cases:
  - testRegisterWithoutOptionalLoggers
  - testRegisterWithoutDefaultChannel
  - testRegisterWithEmptyChannels
- Implement callback-based assertions for addLogger calls
- Improve test coverage for various configuration scenarios
- Modified .env.example and config/logging.php to include new logging configuration options.
- Implemented LoggerConfigurableFactory interface for standardized configuration initialization.
- Created LoggerFormatterFactory to handle dynamic formatter creation based on configuration.
- Enhanced LoggerHandlerFactory and LoggerProcessorFactory to dynamically create handlers and processors with configuration overrides.
- Added new LoggerConfiguration methods to support dynamic and configurable log creation.
- Updated LoggerFactory to utilize new factories for handler, processor, and formatter creation.
- Improved LoggerRegistry to manage logger instances more effectively.
- Refactored AsyncLogProcessor and created additional metric processors including CpuUsageProcessor, ExecutionTimeProcessor, and MetricsProcessor.
- Renamed MemoryUsageProcessor to Metric/MemoryUsageProcessor for better organization.
- Updated LoggerServiceProvider to use new factories and configuration methods.
- Created ReflectionFactoryTrait to handle dynamic instance creation with constructor parameter filtering.
- Added ConfigurationValidator to validate logging configurations.
- Updated test cases in MemoryUsageProcessorTest and LoggerServiceProviderTest to reflect changes.
- Ensured compatibility with application by updating tests/application.php.
…rovider

- Implement LoggerHandlerFactory with improved factory methods for handlers
- Ensure channel and optional handler configurations are correctly merged
- Add method to retrieve handlers configuration cleanly
- Update LoggerServiceProvider to include better registration of default, emergency, and optional loggers
- Refactor logger configuration for better clarity and maintainability
- Enhance logging configuration file for better separation of concerns and flexibility
- Added constants OPTIONAL_LOG_KEYS and OPTIONAL_LOGS to define minimum required keys and the list of optional logs.
- Implemented validateOptionalLogs method to validate optional logs (query, performance, error) in the configuration.
- Ensured that optional logs have at least 'enabled' and 'channel' keys.
- Added checks to ensure 'handlers' and 'processors' are arrays if present in optional logs.
- Integrated validateOptionalLogs into the main validate method.
- Fixed code style issues in LoggerHandlerFactory.php, LoggerConfiguration.php, LoggerProcessorFactory.php, ReflectionFactoryTrait.php, and ConfigurationValidator.php using PHP CS Fixer.
- Enhanced LoggerManager to support optional context parameters.
- Added logic to apply thresholds only if context parameters are passed.
- Updated LoggerFactory to configure performance and query loggers with thresholds.
- Ensured loggers function normally when context parameters are not provided.
- Modified config/logging.php: Updated configuration settings for logging channels and handlers.
- Deleted invalidPath: Removed unused or invalid path from the project.
- Modified src/Formatter/AbstractFormatter.php: Improved SRP compliance and refactored formatter handling.
- Modified src/Handler/LoggerHandlerFactory.php: Refactored factory logic to enhance clarity and maintainability.
- Modified src/LogRecord.php: Updated LogRecord to align with new formatter handling.
- Modified src/Processor/IntrospectionProcessor.php: Improved semantics and logic for stack trace depth handling.
- Modified tests/application.php: Updated tests to reflect changes in logging configuration and processing.
…hannel-specific processors

- Updated LoggerProcessorFactory to ensure processors from both channel configurations and optional configurations are correctly merged.
- Adjusted the createProcessors method to handle the merging of processor configurations.
- Ensured that the processors are instantiated with the correct configuration parameters.
- Added utility methods to handle configuration merging and validation.
- Updated .env.example and config/logging.php for new configurations.
- Added AnonymizerStrategy interface.
- Refactored Anonymizer classes for better design and maintainability.
- Removed unnecessary ExceptionHandler.
- Improved and added new handlers and processors.
- Enhanced Encryptor and renamed ConfigHelper to Config.
- Added new test configurations and updated application tests.
- Moved color definitions for log levels into the LogLevel enum.
- Updated ConsoleColorFormatter to use the getColor method from the LogLevel enum.
- This change centralizes color logic within the LogLevel enum, improving code organization and maintainability.
- Update SlackHandler configuration to use bot token
- Modify SlackClient to utilize Slack's chat.postMessage API
- Update SlackHandler to work with the new SlackClient implementation
- Adjust CurlClient to support authorization headers
- Add environment variables for SLACK_BOT_TOKEN and SLACK_CHANNEL
- Improve error handling and Slack API response processing
- Prevent uninitialized property access errors by ensuring $formatter is initialized in AbstractHandler.
- Update all handler constructors to accept a LogFormatter parameter and pass it to the parent constructor.
- Set a default LineFormatter if no formatter is provided.
… method

- Moved the context construction logic from the process() method into a new private method buildContext().
- This enhances code readability and adheres to the Single Responsibility Principle (SRP) by separating the concerns of processing and context building.
- Improves maintainability by centralizing the context logic, making future modifications easier.
…ty classes

- Refactored SlackClient with Builder Pattern for better dependency injection
- Improved error handling and added constants in ConfigGenerator
- Cleaned up redundant code in CurlClient and added proper error handling
- Enhanced MetricsProcessor logic for better performance
- Simplified HttpRequest and ServerHttpRequest classes
- Improved asset handling logic in AssetPublisher
- Refined test cases in test_config.php for improved test coverage and clarity
…nused HttpRequest

- Adjust exception message assertions in LoggerRegistryTest to handle correct quoting
- Refactor SlackClient to improve resilience with CircuitBreaker and Retry mechanisms
- Delete obsolete HttpRequest class and update related references
- Improve test coverage for Anonymizer and add pattern handling
- Update 'LoggerFactoryTest.php' to correct errors and ensure compatibility with the current configuration.
- Modify 'LoggerRegistryTest.php' to improve test coverage and verify proper logger registration.
- Complete and fix 'LoggerServiceProviderTest.php', resolving issues related to undefined methods and type incompatibilities, ensuring all tests pass.
- Modified LoggerConfigurationTest.php to improve test coverage
- Updated LoggerFactoryTest.php for consistency with recent changes
- Deleted unused test_config.php file

These changes enhance the test suite for the logging system,
ensuring better coverage and removing redundant files.
- Added test for processing of non-trackable log levels, ensuring no modification of the log record.
- Added test for processing of trackable log levels, verifying introspection data is added to the context.
- Added test to validate respect for custom stack depth in introspection.
- Added test to ensure original context is preserved when introspection is applied.
- Added test for handling invalid trace depth in introspection with reflection.
- Deleted tests/Handler/ExceptionHandlerTest.php
- Deleted tests/Util/ConfigHelperTest.php
- Improve exception handling and error reporting in LoggerHandlerFactory
- Add unit tests for LoggerHandlerFactory and LoggerFormatterFactory
- Add tests for AssetPublisher and ComposerScripts utilities
- Include test traits under tests/Trait/
- Update .gitignore to exclude test/build artifacts
- Refactored LoggerProcessorFactory and LoggerHandlerFactory to handle missing or empty processor/handler configurations gracefully without throwing exceptions.
- Enhanced configurability and flexibility by improving initialization methods for logging components.
- Added new unit tests for QueryLogger, MetricsProcessor, AnonymizerProcessor, and EncryptionProcessor, increasing overall test coverage.
- Removed obsolete LoggerHandlerFactory test under Formatter namespace.
- Updated mock expectations and assertions in existing tests for handlers and processors to ensure accurate and consistent behavior.
- Cleaned up unnecessary dependencies and ensured better isolation in test cases.
@walmir-silva walmir-silva merged commit b9c0c45 into main Sep 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant